Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING: better json encoding + marshalling/unmarshalling #34

Merged
merged 2 commits into from
Oct 13, 2020

Conversation

hacdias
Copy link
Member

@hacdias hacdias commented Oct 9, 2020

Unfortunately, sdk-go is the source of truth for Testground on some types. Right now I'm just changing the names in the JSON encoding so when we type them in sdk-js, we don't end up with a weird mix of capitalized and uncapitalized things. However, it is my opinion that we should move this types to the main repo!

It is a breaking change because both Testground and this need to be updated in order to work.

@nonsense
Copy link
Member

nonsense commented Oct 9, 2020

I think across Testground we are mostly using snake_case for JSON encoded values, maybe use that here as well instead of camelCase.

@hacdias
Copy link
Member Author

hacdias commented Oct 9, 2020

Hmmmm... The thing is: this are values that the developer/user has to write. And JavaScript translates literally to JSON. And JavaScript is, by default, camelCase 🐪 .

This is the smallest change subset I can make. I'm not using it for now and I'm leaving this as a draft until I'm sure the sdk-js works correctly. After that, I'll take a look at this again.

This piece of code of the example I'm building:

image

It's a bit odd to see that the network configuration is literally the only thing that is not camel case. It could induce in errors. We could also have a simple function on the sdk-js side of things that would convert the object to match the current sdk-go version too! That wouldn't be a problem either!

Nevertheless, I think testground/testground should be the repository dictating the format, and not sdk-go! It's easier to keep track.

@raulk
Copy link
Contributor

raulk commented Oct 9, 2020

The upper case is a side effect of default Go JSON serialisation. I'm happy to normalise with the rest of our JSON schemas, which use snake case :-) camelCase is 🤮 for API endpoints.

@raulk
Copy link
Contributor

raulk commented Oct 9, 2020

(Implementing a function to convert the casing should be simple -- there is always going to be one or another language that is aggrieved)

License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
@hacdias hacdias changed the title BREAKING: better json encoding BREAKING: better json encoding + marshalling/unmarshalling Oct 10, 2020
@hacdias
Copy link
Member Author

hacdias commented Oct 10, 2020

So this is enough for me. This PR does the following to help standardize the formats:

  • Uses snake_case to make it consistent with the rest of the API
  • Moves runtime.IPNet to ptypes.IPNet
  • Replaces network.Config net.IPNets with ptypes.IPNet which (de)serializes in a beautiful CIDR string!

@hacdias hacdias marked this pull request as ready for review October 10, 2020 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants